var isIE = "\v"=="v";
function addOption(oSelect, oOption){
	if(isIE){
		oSelect.add(oOption);
	}else{
		oSelect.add(oOption,null);
	}
}
function $(id){
	return document.getElementById(id);
}
function init(){
	populateYear();
	populateMonth();
	$('year').onchange = populateDay;
	$('month').onchange = populateDay;
	populateDay();
}
function populateYear(){
	var oYear = $('year');
	var arrOptions = getYearOptions();
	for(var i in arrOptions){
		var oOption = new Option(arrOptions[i], arrOptions[i],false,false);
		addOption(oYear,oOption);
	}
}
function populateMonth(){
	var oMonth = $('month');
	var arrOptions = getMonthOptions();
	for(var i in arrOptions){
		var oOption = new Option(arrOptions[i], arrOptions[i],false,false);
		addOption(oMonth,oOption);
	}
}
function populateDay(){
	var oDay = $('day');
	oDay.options.length = 0;
	var arrOptions = getDayOptions();
	for(var i in arrOptions){
		var oOption = new Option(arrOptions[i], arrOptions[i],false,false);
		addOption(oDay,oOption);
	}
}
function getYearOptions(){
	var arrYearOptions = [];
	var currentYear = new Date().getFullYear();
	for(var i = 60; i > 0; i--) {
		arrYearOptions[i] = currentYear - i;
	}
	return arrYearOptions;
}
function getMonthOptions(){
	var arrMonthOptions = [];
	for(var i = 0; i < 12; i++) {
		arrMonthOptions[i] = i + 1;
	}
	return arrMonthOptions;
}
function getDayOptions(){
	var oYear = $('year');
	var oMonth = $('month');
	var max = 31;
	switch(parseInt(oMonth.value,10)){
		case 4:
		case 6:
		case 9:
		case 11:
			max = 30;
			break;
		case 2:
			max = isLeapYear(oYear.value) ? 29: 28;
			break;
	}
	var arrOptions = [];
	for(var i = 1; i <= max; i++) {
		arrOptions[i - 1] = i;
	}
	return arrOptions;
}
function isLeapYear(y) {
	return (y%4==0 && y%100 !=0) || y%400 == 0;
}